package com.lyncs.ods.modules.website.controller;

import com.lyncs.ods.common.api.CommonResult;
import com.lyncs.ods.common.web.RequestHolder;
import com.lyncs.ods.modules.website.model.CustomerInfo;
import com.lyncs.ods.modules.website.service.CustomerInfoService;
import com.lyncs.ods.req.SaveCompanyReq;
import com.lyncs.ods.req.SaveContactReq;
import com.lyncs.ods.resp.UserCompanyResp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author alex
 * @date 2022/6/6 00:03
 * @description
 */
@RestController
@RequestMapping("/web")
@Api(tags = {"官网相关接口"})
public class WebController {

    @Autowired
    private CustomerInfoService customerInfoService;

    @GetMapping("/phone")
    @ApiOperation(value = "下发体验单据链接")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone", value = "手机号码", dataType = "String", paramType = "query"),
    })
    public CommonResult<String> saveContactInfo(@RequestParam("phone") String phone) {
        CustomerInfo customerInfo = new CustomerInfo()
                .setUsername(null)
                .setChannel(1)
                .setPhone(phone)
                .setCompanyName(null)
                .setCreateTime(RequestHolder.getRequestDateTime());
        customerInfoService.save(customerInfo);
        return CommonResult.success("链接待定");
    }

    @PostMapping("/contact")
    @ApiOperation(value = "保存客户联系信息")
    public CommonResult<?> saveContactInfo(@Valid @RequestBody SaveContactReq req) {
        CustomerInfo customerInfo = new CustomerInfo()
                .setUsername(req.getUsername())
                .setChannel(2)
                .setPhone(req.getPhone())
                .setCompanyName(req.getCompanyName())
                .setCreateTime(RequestHolder.getRequestDateTime());
        customerInfoService.save(customerInfo);
        return CommonResult.success();
    }
}
